package com.yygo.dao.hibernate;

import com.yygo.dao.CountyDao;
import com.yygo.model.County;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 * Created by tiansha on 2015/6/24.
 */
@Repository("countyDao")
public class CountyDaoHibernate extends GenericDaoHibernate<County, Long> implements CountyDao {
    public CountyDaoHibernate() {
        super(County.class);
    }

    @Override
    public County findIdByName(String countyName, String cityName) {

        Criteria criteria = getSession().createCriteria(County.class).add(Restrictions.eq("name",countyName));
        criteria.createAlias("city", "city").add(Restrictions.eq("city.name", cityName));
        criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        County county = (County) criteria.uniqueResult();
       // criteria.setProjection(Projections.rowCount());
        return county;

    }
}
